package ai.tubes.iris;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class KnowledgeEditor2Activity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.knowedit2);
		alertDialog = new AlertDialog.Builder(this).create();
		mesininferensi = new ai.tubes.iris.knowledge.inferenceengine();

		TableField = mesininferensi.getInferenceTable(); // untuk ngambil data
		
		bronkialisbawah  = (EditText) findViewById(R.id.txtbronkialisbawah);
		bronkialisatas  = (EditText) findViewById(R.id.txtbronkialisatas);
		jantungbawah  = (EditText) findViewById(R.id.txtjantungbawah);
		jantungatas  = (EditText) findViewById(R.id.txtjantungatas);
		limpabawah  = (EditText) findViewById(R.id.txtlimpabawah);
		limpaatas  = (EditText) findViewById(R.id.txtlimpaatas);
		kolonnaikbawah  = (EditText) findViewById(R.id.txtkolonnaikbawah);
		kolonnaikatas  = (EditText) findViewById(R.id.txtkolonnaikatas);
		kolonturunbawah  = (EditText) findViewById(R.id.txtkolonturunbawah);
		kolonturunatas  = (EditText) findViewById(R.id.txtkolonturunatas);
		ususkecilbawah  = (EditText) findViewById(R.id.txtususkecilbawah);
		ususkecilatas  = (EditText) findViewById(R.id.txtususkecilatas);
		kolonsigmoidbawah  = (EditText) findViewById(R.id.txtkolonsigmoidbawah);
		kolonsigmoidatas  = (EditText) findViewById(R.id.txtkolonsigmoidatas);
		ususbuntubawah  = (EditText) findViewById(R.id.txtususbuntubawah);
		ususbuntuatas  = (EditText) findViewById(R.id.txtususbuntuatas);
		lambungbawah  = (EditText) findViewById(R.id.txtlambungbawah);
		lambungatas = (EditText) findViewById(R.id.txtlambungatas);
		
		setTextValue();
		
		//Button prev
		mPrev	= (Button)findViewById(R.id.buttonprev);
		mPrev.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				startActivity(new Intent(KnowledgeEditor2Activity.this.getApplicationContext(), KnowledgeEditorActivity.class));
			}
		});
		
		//button close
		mclose	= (Button)findViewById(R.id.buttonclose2);
		mclose.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				startActivity(new Intent(KnowledgeEditor2Activity.this.getApplicationContext(), MainMenuActivity.class));
			}
		});
		
		//button apply
		mapply	= (Button)findViewById(R.id.buttonapply2);
		mapply.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				getTextValue();
				mesininferensi.setInferenceTable(TableField);
				mesininferensi.writeInferenceFile();
			}
		});
		
		//Button update
		mupdate	= (Button)findViewById(R.id.buttonupdate);
		mupdate.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				mesininferensi.serverUpdate();
			}
		});
		
		/*alert text for learning*/
		
		lblbronkialis	= (TextView)findViewById(R.id.lblbronkialis);
		lblbronkialis.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Bronchialis"));
			}
		});
		
		lbljantung	= (TextView)findViewById(R.id.lbljantung);
		lbljantung.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Jantung"));
			}
		});
		
		lbllimpa	= (TextView)findViewById(R.id.lbllimpa);
		lbllimpa.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Limpa"));
			}
		});
		
		lblkolonnaik	= (TextView)findViewById(R.id.lblkolonnaik);
		lblkolonnaik.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("KolonMenaik"));
			}
		});
		
		lblkolonturun	= (TextView)findViewById(R.id.lblkolonturun);
		lblkolonturun.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("KolonMenurun"));
			}
		});
		
		lblususkecil	= (TextView)findViewById(R.id.lblususkecil);
		lblususkecil.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("UsusKecil"));
			}
		});
		
		lblkolonsigmoid	= (TextView)findViewById(R.id.lblkolonsigmoid);
		lblkolonsigmoid.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("KolonSigmoid"));
			}
		});
		
		lblususbuntu	= (TextView)findViewById(R.id.lblususbuntu);
		lblususbuntu.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("UsusBuntu"));
			}
		});
		
		lbllambung	= (TextView)findViewById(R.id.lbllambung);
		lbllambung.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0) {
				showmessagebox(mesininferensi.SaranLearningData("Lambung"));
			}
		});
		
	}
	private void showmessagebox(String Message)
	{
		alertDialog.setMessage(Message);
		alertDialog.show();
		
	}
	private void setTextValue() {
		bronkialisbawah.setText(TableField[1][10]);
		bronkialisatas.setText(TableField[2][10]);
		jantungbawah.setText(TableField[1][11]);
		jantungatas.setText(TableField[2][11]);
		limpabawah.setText(TableField[1][12]);
		limpaatas.setText(TableField[2][12]);
		kolonnaikbawah.setText(TableField[1][13]);
		kolonnaikatas.setText(TableField[2][13]);
		kolonturunbawah.setText(TableField[1][14]);
		kolonturunatas.setText(TableField[2][14]);
		ususkecilbawah.setText(TableField[1][15]);
		ususkecilatas.setText(TableField[2][15]);
		kolonsigmoidbawah.setText(TableField[1][16]);
		kolonsigmoidatas.setText(TableField[2][16]);
		ususbuntubawah.setText(TableField[1][17]);
		ususbuntuatas.setText(TableField[2][17]);
		lambungbawah.setText(TableField[1][18]);
		lambungatas.setText(TableField[2][18]);
	}

	private void getTextValue() {
		TableField[1][10] = bronkialisbawah.getText().toString();
		TableField[2][10] = bronkialisatas.getText().toString();
		TableField[1][11] = jantungbawah.getText().toString();
		TableField[2][11] = jantungatas.getText().toString();
		TableField[1][12] = limpabawah.getText().toString();
		TableField[2][12] = limpaatas.getText().toString();
		TableField[1][13] = kolonnaikbawah.getText().toString();
		TableField[2][13] = kolonnaikatas.getText().toString();
		TableField[1][14] = kolonturunbawah.getText().toString();
		TableField[2][14] = kolonturunatas.getText().toString();
		TableField[1][15] = ususkecilbawah.getText().toString();
		TableField[2][15] = ususkecilatas.getText().toString();
		TableField[1][16] = kolonsigmoidbawah.getText().toString();
		TableField[2][16] = kolonsigmoidatas.getText().toString();
		TableField[1][17] = ususbuntubawah.getText().toString();
		TableField[2][17] = ususbuntuatas.getText().toString();
		TableField[1][18] = lambungbawah.getText().toString();
		TableField[2][18] = lambungatas.getText().toString();

	}
	AlertDialog alertDialog;
	ai.tubes.iris.knowledge.inferenceengine mesininferensi;
	String[][] TableField;
	private Button mPrev,mclose,mapply,mupdate;
	private EditText bronkialisbawah,bronkialisatas,jantungbawah,jantungatas,limpabawah,limpaatas,kolonnaikbawah,kolonnaikatas,kolonturunbawah,kolonturunatas,ususkecilbawah,ususkecilatas,kolonsigmoidbawah,kolonsigmoidatas,ususbuntubawah,ususbuntuatas,lambungbawah,lambungatas;
	private TextView lblbronkialis,lbljantung,lbllimpa,lblkolonnaik,lblkolonturun,lblususkecil,lblkolonsigmoid,lblususbuntu,lbllambung;
}
